

package com.hazelcast.internal.monitor.impl;

import com.hazelcast.internal.metrics.Probe;
import com.hazelcast.internal.util.Clock;

import java.util.Map;

import static com.hazelcast.internal.metrics.MetricDescriptorConstants.USER_CODE_NAMESPACE_RESOURCE_COUNT;
import static com.hazelcast.internal.metrics.MetricDescriptorConstants.USER_CODE_NAMESPACE_UPDATE_TIME;
import static com.hazelcast.internal.metrics.ProbeUnit.COUNT;
import static com.hazelcast.internal.metrics.ProbeUnit.MS;

public class LocalUserCodeNamespaceStatsImpl implements LocalUserCodeNamespaceStats {

    @Probe(name = USER_CODE_NAMESPACE_UPDATE_TIME, unit = MS)
    private final long updateTime;
    private Map<String, LocalUserCodeNamespaceResourceStats> localUserCodeNamespaceResourceStats;

    public LocalUserCodeNamespaceStatsImpl() {
        updateTime = Clock.currentTimeMillis();
    }

    @Override
    public long getCreationTime() {
        return updateTime;
    }

    @Probe(name = USER_CODE_NAMESPACE_RESOURCE_COUNT, unit = COUNT)
    @Override
    public long getResourcesCount() {
        return localUserCodeNamespaceResourceStats.size();
    }

    public void setLocalUserCodeNamespaceResourceStats(Map<String, LocalUserCodeNamespaceResourceStats> localUserCodeNamespaceResourceStats) {
        this.localUserCodeNamespaceResourceStats = localUserCodeNamespaceResourceStats;
    }

    @Override
    public Map<String, LocalUserCodeNamespaceResourceStats> getResources() {
        return localUserCodeNamespaceResourceStats;
    }
}
